<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:include="css :: css">

</head>
<link href="/js/jquery.icheck/skins/square/blue.css" rel="stylesheet">
<link href="/css/custom.css" rel="stylesheet">
<body style="overflow: hidden;opacity: 1">

<div id="cl-wrapper" style="padding-top: 0">
    <div class="container-fluid" id="pcont">
        <div class="cl-mcont">
            <div class="row">
                <div class="col-md-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>设置会员密价</h5>
                        </div>
                        <div class="ibox-content">
                            <div class="row">
                                <form id="quickSetting">
                                    <dl class="dl-horizontal">
                                        <dt>搜索会员名称：</dt>
                                        <dd>
                                            <div class="col-sm-6">
                                                <input class="form-control" type="text" name="userAccount"
                                                       id="userAccount"
                                                       placeholder="请输入会员编号,不填默认设置权益模板密价">
                                            </div>
                                            <div class="col-sm-6"><span class="input-group-btn">
                                                    <button class="btn btn-primary" type="button"
                                                            id="searchUsers">搜索 </button>
                                                </span>
                                            </div>
                                        </dd>
                                        <dd>
                                            <div class="col-sm-12">
                                                <span style="color: red">多个会员编号，以英文逗号隔开。 </span>
                                            </div>
                                        </dd>
                                        <dt>
                                            <label class="icheck" style="margin-right:10px; ">
                                                会员名称：
                                                <input type="checkbox" value="0" id="checkUserAll">全选
                                            </label>
                                        </dt>
                                        <dd>
                                            <div class="col-sm-6" id="userSet">
                                            </div>
                                        </dd>
                                        <dt>搜索产品名称：</dt>
                                        <dd>
                                            <div class="col-sm-6">
                                                <select class="selectpicker" title="运营商" onchange="operatorChange(this)"
                                                        id="cardOperatorId"
                                                        data-live-search="true">
                                                </select>
                                            </div>
                                        </dd>
                                        <dt>
                                            <label class="icheck" style="margin-right:10px; ">
                                                产品名称：
                                                <input type="checkbox" value="0" id="checkProductAll">全选
                                            </label>
                                        </dt>
                                        <dd>
                                            <div class="col-sm-6" id="productSet">
                                            </div>
                                        </dd>
                                        <dt>操作状态：</dt>
                                        <dd>
                                            <div class="col-sm-6">
                                                <select class="form-control " name="status" id="status"
                                                        onchange="reloadDiscount(this)">
                                                    <option value="1">新增</option>
                                                    <option value="0">修改</option>
                                                    <option value="4">删除</option>
                                                </select>
                                            </div>
                                        </dd>
                                        <dt>价格：</dt>
                                        <dd>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="minPrice" id="minPrice">
                                            </div>
                                        </dd>
                                        <dt id="xianyuPrice_id">闲鱼佣金比：</dt>
                                        <dd>
                                            <div class="col-sm-6">
                                                <input type="number" class="form-control" name="xianyuPrice"
                                                       min="0" max="1" id="xianyuPrice">
                                            </div>
                                        </dd>
                                    </dl>
                                    <div class="hr-line-dashed"></div>
                                    <div class=" col-md-4 col-md-offset-3">
                                        <button class="btn btn-info" type="button" id="formSubmit">提交设置</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="js :: js"></div>
<script type="text/javascript" src="js/jquery.icheck/icheck.min.js"></script>
<script>
    $(function () {
        $("#xianyuPrice_id").hide();
        $("#xianyuPrice").hide();
        $.ajax({
            type: "POST",
            url: "/CardProductController/queryAllCardOperatorList",
            dataType: "json",
            success: function (data) {
                $("#cardOperatorId").html("");
                var str1 = "<option value=\"\">全部</option>";
                var str = "";
                if (data != null && data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        str += '<option value=' + data[i].cardOperatorId + '>' + data[i].cardOperatorName + '</option>'
                    }
                }
                $("#cardOperatorId").append(str1 + str);
                //缺一不可  
                $('.selectpicker').selectpicker('refresh');
                $('.selectpicker').selectpicker('render');
            },
            beforeSend: function () {
            }
        });
    });
    $("#searchUsers").click(function () {
        var xianyuUserAccount = '18615327155';
        var userAccount = $.trim($("#userAccount").val());
        if (userAccount.indexOf(xianyuUserAccount) != -1 && userAccount.indexOf(",") != -1) {
            layer.msg("仅支持单独设置闲鱼会员密价");
            return;
        }
        $.post("/productPrice/queryUserByAccount", {userAccount: $.trim($("#userAccount").val())}, function (data) {
            //隐藏闲鱼价格
            if (userAccount.indexOf(xianyuUserAccount) != -1) {
                $("#xianyuPrice_id").show();
                $("#xianyuPrice").show();
            } else {
                $("#xianyuPrice_id").hide();
                $("#xianyuPrice").hide();
            }
            if (data == null || data.length == 0) {
                layer.msg("请输入正确会员编号");
                return;
            }
            var str = '';
            for (var i = 0; i < data.length; i++) {
                str += '<label class="icheck" style="margin-right:10px;">' +
                    '<input name="userIds" type="checkbox" value="' + data[i].userId + '">' + data[i].supInfo.name + '</label>';
            }
            $("#userSet").html(str);
        });
    })

    function operatorChange(obj) {
        if (obj == null || obj.value == null) {
            return;
        }
        $.post("/cardPrice/queryProductList", {productType: obj.value}, function (data) {
            if (data == null || data.length == 0) {
                $("#productSet").html("");
                layer.msg("该卡种类型下暂无产品");
                return;
            }
            var str = '';
            for (var i = 0; i < data.length; i++) {
                str += '<label class="icheck" style="margin-right:10px;">' +
                    '<input name="productIds" type="checkbox" value="' + data[i].id + '">' + data[i].cardProductName + '</label>';
            }
            $("#productSet").html(str);
        });
    }


    $("#formSubmit").click(function () {
        var title = "<span style='color: green;font-size: 15px'>设置会员密价,确定提交吗?</span>";
        if ($('input[name=userIds]:checked').length < 1) {
            title = "<span style='color:red;font-size: 15px'>当前未选择会员,将默认设置权益模板密价,确定提交吗?</span>"
        }
        if ($('input[name=productIds]:checked').length < 1) {
            layer.msg("请选择产品");
            return;
        }
        $.confirm({
            title: '确认!',
            content: title,
            confirm: function () {
                submitForm();
            }
        })
    });


    function submitForm() {
        $.post("/cardPrice/setUpCardPrice", $("#quickSetting").serialize(), function (data) {
            layer.msg(data.message);
        }).error(function (e) {
            layer.msg(e);
        });
    }</script>
<script>
    $('#checkProductAll').on('ifChecked', function (event) {
        $("#productSet input").iCheck("check");
    });
    $('#checkProductAll').on('ifUnchecked', function (event) {
        $("#productSet input").iCheck("uncheck");
    });
    $('#checkUserAll').on('ifChecked', function (event) {
        $("#userSet input").iCheck("check");
    });
    $('#checkUserAll').on('ifUnchecked', function (event) {
        $("#userSet input").iCheck("uncheck");
    });
</script>
</body>
</html>
